﻿//-----------------------------------------------------------------------
// <copyright file="BasicDatabaseTest.cs" company="NextLine Software">
//     Copyright (c) NextLine Software. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace NextLine.Data.SQLite.Tests
{
    using System;
    using System.Data;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class BasicDatabaseTest
    {
        [TestMethod]
        public void DatabaseOpen()
        {
            string databaseName = Guid.NewGuid().ToString();
            IDbConnection connection = null;
            using (connection = new SQLiteConnection(databaseName))
            {
                Assert.AreEqual(databaseName, connection.ConnectionString);
                Assert.AreEqual(databaseName, connection.Database);
                Assert.AreEqual(ConnectionState.Closed, connection.State);
                connection.Open();
                Assert.AreEqual(ConnectionState.Open, connection.State);
            }

            Assert.IsNotNull(connection);
            Assert.AreEqual(ConnectionState.Closed, connection.State);
        }

        [TestMethod]
        public void DatabaseCloseTest()
        {
            string databaseName = Guid.NewGuid().ToString();
            IDbConnection connection = new SQLiteConnection(databaseName);
            Assert.AreEqual(ConnectionState.Closed, connection.State);
            connection.Open();
            Assert.AreEqual(ConnectionState.Open, connection.State);
            connection.Close();
            Assert.AreEqual(ConnectionState.Closed, connection.State);

        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void NullConnectionStringTest()
        {
            var connection = new SQLiteConnection();
            connection.ConnectionString = null;
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void EmptyConnectionStringTest()
        {
            var connection = new SQLiteConnection();
            connection.ConnectionString = string.Empty;
        }

        [TestMethod]
        public void ConnectionTimeoutTest()
        {
            var connection = new SQLiteConnection();
            Assert.AreEqual(0, connection.ConnectionTimeout);
        }

        [TestMethod]
        [ExpectedException(typeof(NotSupportedException))]
        public void ChangeDatabaseTest()
        {
            var connection = new SQLiteConnection();
            connection.ChangeDatabase("new db");
        }
    }
}
